package red.book.until;

/**
 * windows 下 scanner.hashNext() 会一直等待， 按CTRL + (C | Z | D) 都不行， 所以改造下。
 * Input:
1
2
3
4
NaN
 * Output:
Average is 2.50000

 * @author wangbingwu
 *
 */
public class Average {
	public static void main(String[] args) {
		// 取StdIn中所有数的平均值
		double sum = 0.0;
		int cnt = 0;
		
		while (!StdIn.isEmpty()) { // 读取一个数并计算累计之和
			double readDouble = StdIn.readDouble();
			if(Double.isNaN(readDouble)) {
				break;
			}
			sum += readDouble;
			cnt++;
		}
		double avg = sum / cnt;
		
		StdOut.printf("Average is %.5f\n", avg);
	}
}
